package edu.pku.sei.modeler.model.structure;

import org.eclipse.draw2d.geometry.Point;

import edu.pku.sei.modeler.model.structure.MetaBendPoint;
import edu.pku.sei.modeler.model.structure.MetaLink;
import edu.pku.sei.modeler.model.structure.MetaNode;

public class HandlerActivityLocator {
	private MetaNode node;
	
	public HandlerActivityLocator(MetaNode node)
	{
		this.node = node;
	}
	public void reLocate(Point displace)
	{
		if (node.getOutgoings().size() > 0){
		MetaLink controlflow = (MetaLink)node.getOutgoings().get(0);
		if (controlflow != null) 
		{
			MetaNode activity = controlflow.getTarget();
			activity.setLocationX(activity.getLocationX() + displace.x);
			activity.setLocationY(activity.getLocationY() + displace.y);
			MetaBendPoint bendpoint = (MetaBendPoint)controlflow.getBendPoints().get(0);
		
			bendpoint.x = node.getLocationX() + node.getWidth() / 2;
			bendpoint.y = activity.getLocationY()+ activity.getHeight() / 2;
			if ((bendpoint.x > activity.getLocationX()) && (bendpoint.x < activity.getLocationX() 
					+ activity.getWidth())) 
				bendpoint.y = (activity.getLocationY() + node.getLocationY() + node.getHeight()) / 2; 
		}
		}
	}

}
